package com.pureut.storage.service.impl;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.storage.domain.*;
import com.pureut.storage.domain.system.domain.SysDocument;
import com.pureut.storage.dto.*;
import com.pureut.storage.export.PickingReturnsExport;
import com.pureut.storage.mapper.*;
import com.pureut.storage.service.OutboundLogService;
import com.pureut.storage.service.PickingReturnsDetailService;
import com.pureut.storage.service.PickingReturnsService;
import com.pureut.storage.service.WmsStockInfoService;
import com.pureut.storage.util.UnitUtil;
import com.pureut.storage.utils.DocumentTypeEnum;
import com.pureut.storage.utils.GenerationMethodEnum;
import com.pureut.storage.vo.*;
import com.sale.common.core.constant.CacheNames;
import com.sale.common.core.domain.R;
import com.sale.common.core.exception.GlobalException;
import com.sale.common.core.utils.bean.BeanUtils;
import com.sale.common.dict.utils.DictUtils;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.common.redis.utils.CacheUtils;
import com.sale.common.satoken.utils.LoginHelper;
import com.sale.system.api.*;
import com.sale.system.api.domain.SysAuxiliary;
import com.sale.system.api.domain.SysDictData;
import com.sale.system.api.domain.SysUser;
import com.sale.system.api.domain.dto.SysDocumentResultDto;
import com.sale.system.api.domain.vo.SysAuditHistoryVo;
import com.sale.system.api.model.MaterialUnitDto;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: CM
 * @date: 2022/12/30  16:37
 * @Desc: 委外退货
 */
@Service
public class PickingReturnsServiceImpl extends ServiceImpl<PickingReturnsMapper, PickingReturns> implements PickingReturnsService {

    @Resource
    private PickingReturnsMapper pickingReturnsMapper;

    @Resource
    private PickingReturnsDetailMapper pickingReturnsDetailMapper;

    @Resource
    private PickingReturnsDetailService pickingReturnsDetailService;

    @DubboReference
    RemoteMenuService remoteMenuService;

    @Resource
    RemoteUserService remoteUserService;

    @Resource
    WmsStockInfoMapper wmsStockInfoMapper;

    @Resource
    WmsStockInfoService wmsStockInfoService;

    @Resource
    PublicMaterialMapper publicGoodsMapper;

    @Resource
    StockOutInfoDetailMapper stockOutInfoDetailMapper;

    @Resource
    WarehouseServiceImpl warehouseService;

    @Resource
    private OutboundLogService outboundLogService;

    @Resource
    private OutboundLogMapper outboundLogMapper;

    @Resource
    private SubcontractReceiptMapper subcontractReceiptMapper;

    @DubboReference
    RemoteCodeService remoteCodeService;

    @DubboReference
    RemoteExamineService remoteExamineService;

    @DubboReference
    RemoteDocumentService remoteDocumentService;

    @Resource
    WarehouseMapper warehouseMapper;

    @Resource
    UnitUtil unitUtil;

    @DubboReference
    RemoteUnitService remoteUnitService;


    /**
     * 委外退货单
     *
     * @param pickingReturnsVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addReturns(PickingReturnsVo pickingReturnsVo) throws Exception {
        //取出返工出库单列表
        List<PickingReturnsDetaillVo> list = pickingReturnsVo.getList();
        if (list.size() == 0) {
            throw new GlobalException("请至少添加一条物料明细");
        }

        int insert = 0;
        //定义物料id
        Long productId = 0L;

        //定义物料编码
        String materialCode = "";

        //定义物料类别
        String category = "";

        String sn = remoteCodeService.authorityCoding("warehouse:outbound:subcontout:list");
        if (sn == null) {
            throw new GlobalException("该单据未进行配置,无法生成单据编码");
        }

        for (PickingReturnsDetaillVo pickingReturnsDetaillVo : list) {

            //获取物料id
            productId = pickingReturnsDetaillVo.getProductId();

            category = pickingReturnsDetaillVo.getCategory();

            materialCode = pickingReturnsDetaillVo.getItemCode();

            //新增返工出库单明细
            PickingReturnsDetail pickingReturnsDetaill = new PickingReturnsDetail();
            //添加批次号
            pickingReturnsDetaill.setBatchNumber(pickingReturnsDetaillVo.getBatchNumber());
            //添加产品号码
            pickingReturnsDetaill.setPdoductNumber(pickingReturnsDetaillVo.getPdoductNumber());
            //添加物料id
            pickingReturnsDetaill.setProductId(pickingReturnsDetaillVo.getProductId());
            //添加物料料号
            pickingReturnsDetaill.setItemCode(pickingReturnsDetaillVo.getItemCode());
            //添加状态为待入库
            pickingReturnsDetaill.setWodStatus(1);
            //添加委外退货单号
            pickingReturnsDetaill.setWodDocNum(sn);


            //添加净重
            pickingReturnsDetaill.setNetWeight(pickingReturnsDetaillVo.getNetWeight());
            //添加物料数量
            pickingReturnsDetaill.setItemNum(pickingReturnsDetaillVo.getItemNum());

            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pickingReturnsDetaillVo.getPdoductNumber()));

            if (wmsStockInfo != null) {
                //添加毛重
                pickingReturnsDetaill.setGrossWeight(wmsStockInfo.getWsiGorssWeight());
                //添加厚度
                pickingReturnsDetaill.setThick(wmsStockInfo.getWsiThick());
                //添加幅宽
                pickingReturnsDetaill.setBreadth(wmsStockInfo.getWsiWidth());
                //添加卷长
                pickingReturnsDetaill.setRollLength(wmsStockInfo.getWsiLength());
                //添加仓储信息
                pickingReturnsDetaill.setWarehouseInfo(wmsStockInfo.getWsiWarehourseInfo());
            }

            insert = pickingReturnsDetailMapper.insert(pickingReturnsDetaill);

        }
        //新增返工出库单信息
        if (insert > 0) {
            PickingReturns pickingReturns = new PickingReturns();
            BeanUtils.copyProperties(pickingReturnsVo, pickingReturns);
            pickingReturns.setCreateUser(LoginHelper.getUsername())
                .setCreateTime(new Date())
                .setDocumentType(DocumentTypeEnum.PICKING_RETURNS.getCode())
                .setMaterialId(productId)
                .setMaterialCode(materialCode)
                .setCategory(category)
                .setWodDocNum(sn)
                .setDeptId(LoginHelper.getDeptId())
                .setWodStatus(1)
                .setPlannedWeight(list.size())
                .setGenerationMode(GenerationMethodEnum.MANUALLY_GENERATED.getCode());
            return save(pickingReturns);
        } else {
            throw new GlobalException("新增失败");
        }
    }

    /**
     * 关结委外退库单
     *
     * @param pickingReturnsVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean closeReturns(PickingReturnsVo pickingReturnsVo) {
        //查询当前单据的状态，只能对待提交，未通过，待审核，审核中，待出库，待交接，状态的单据进行关结
        PickingReturns pickingReturns = pickingReturnsMapper.selectById(pickingReturnsVo.getId());
        //取出当前的单据状态
        int wodStatus = pickingReturns.getWodStatus();
        if (wodStatus == 7 || wodStatus == 8) {
            throw new GlobalException("不可对已关结和已完成状态的单据进行重复关结");
        }


        try {
            //如果单据状态是待检验，入库的物料显示在库，关联品质检验单状态更新为撤销
            if (wodStatus == 9 || wodStatus == 10 || wodStatus == 6) {
                //根据单号获取生产领料单明细
                List<PickingReturnsDetail> pickingRestDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));

                List<WmsStockInfo> wmsStockInfos = new ArrayList<>();

                for (PickingReturnsDetail pickingReturnsDetail : pickingRestDetailList) {
                    WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pickingReturnsDetail.getPdoductNumber()).eq(WmsStockInfo::getWsiMaterialStatus, 5));
                    wmsStockInfos.add(wmsStockInfo);
                }

//                if (wmsStockInfos.size()!=0){
//                    boolean b = wmsStockInfoService.removeBatchByIds(wmsStockInfos);
//                }
//
//                if (wodStatus==9){
//                    //如果是待检验删除品质检验单
//                    UpdateQualityStatusVo updateQualityStatusVo = new UpdateQualityStatusVo();
//                    updateQualityStatusVo.setStatus(8);
//                    updateQualityStatusVo.setAssociatedNo(pickingReturns.getWodDocNum());
//                    AjaxResult ajaxResult = qualityFeginService.updateQualityInspectionDocument(updateQualityStatusVo);
//
//
//                    if (!"200".equals(ajaxResult.get("code").toString())){
//                        throw new GlobalException("服务调用失败");
//                    }
//
//                }
            }
        } catch (Exception e) {
            throw new GlobalException("关结失败");
        }


        //取出关结人
        String closeMan = pickingReturns.getCloseMan();
        if (closeMan != null) {
            closeMan = closeMan + "," + LoginHelper.getUsername();
        } else {
            closeMan = LoginHelper.getUsername();
        }

        //修改单据状态未关结，修改关结原因，修改关结人，修改关结时间

        pickingReturns
            .setWodStatus(8).setCloseTime(new Date())
            .setCloseMan(closeMan)
            .setCloseCause(pickingReturnsVo.getCloseCause());
        return updateById(pickingReturns);
    }

    /**
     * 提交审核
     *
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submitReturns(String ids) {
        //将ids根据逗号拆分成数组
        List<String> idStr = Arrays.asList(ids.split(","));
        if (idStr.size() == 0) {
            throw new GlobalException("请至少勾选一条单据");
        }
        //根据ids批量查询出list列表
        List<PickingReturns> pickingReturnsList = pickingReturnsMapper.selectBatchIds(idStr);

        //遍历
        for (PickingReturns pickingReturns : pickingReturnsList) {
            if (pickingReturns.getWodStatus() != 1) {
                throw new GlobalException("只能对状态为“待提交”的单据进行提交操作");
            }
            pickingReturns.setWodStatus(2);

//            //新增审核代办
//            SysWorkbenchAuditAgentVo sysWorkbenchAuditAgentVo = new SysWorkbenchAuditAgentVo();
//
//            sysWorkbenchAuditAgentVo.setDocConfig("warehouse:outbound:subcontout:examine");
//            sysWorkbenchAuditAgentVo.setReceiptName("委外退货");
//            sysWorkbenchAuditAgentVo.setReceiptNumber(pickingReturns.getWodDocNum());//委外单号
//            sysWorkbenchAuditAgentVo.setStatus(1);//待审核
//            sysWorkbenchAuditAgentVo.setReceiptContent("有单据待审核,请及时审核");
//
//            feignService.insertAuditAgent(sysWorkbenchAuditAgentVo);

        }
        return updateBatchById(pickingReturnsList);
    }

    /**
     * 删除委外出库单
     *
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteReturns(String ids) {
        //将ids根据逗号拆分成数组
        List<String> idStr = Arrays.asList(ids.split(","));
        if (idStr.size() == 0) {
            throw new GlobalException("请至少勾选一条单据");
        }
        //根据ids批量查询出list列表
        List<PickingReturns> pickingReturnsList = pickingReturnsMapper.selectBatchIds(idStr);
        List<PickingReturns> doucmentList = new ArrayList<>();
        List<String> doucmentNumber = new ArrayList<>();
        for (PickingReturns entity : pickingReturnsList) {
            if (entity.getGenerationMode() != 2) {
                throw new GlobalException("系统自动生成的单据不可删除");
            }
            if (entity.getWodStatus() == 1 || entity.getWodStatus() == 4) {
                doucmentList.add(entity);
                doucmentNumber.add(entity.getWodDocNum());
            } else {
                throw new GlobalException("只能删除“待出库”或者“未通过”状态的单据");
            }
        }

//        for (PickingReturns entity : pickingReturnsList) {
//            feignService.deleteDoc(entity.getWodDocNum(),"委外退货");
//        }

        //删除对应明细
        List<PickingReturnsDetail> pickingReturnsDetails = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().in(PickingReturnsDetail::getWodDocNum, doucmentNumber));
        if (pickingReturnsDetails.size() > 0) {
            pickingReturnsDetailService.removeBatchByIds(pickingReturnsDetails);
        }
        //删除单据
        return removeBatchByIds(doucmentList);
    }

    /**
     * 修改委外发货单
     *
     * @param pickingReturnsVo
     * @return
     */
    @Override
    public boolean updateReturns(PickingReturnsVo pickingReturnsVo) {
        //判断明细是否至少有一条明细
        List<PickingReturnsDetaillVo> list = pickingReturnsVo.getList();
        if (list.size() == 0) {
            throw new GlobalException("请至少添加一条物料明细");
        }

        //通过物料id查出出库单号
        PickingReturns pickingReturns = pickingReturnsMapper.selectById(pickingReturnsVo.getId());
        int wodStatus = pickingReturns.getWodStatus();
        if (wodStatus != 1 && wodStatus != 4) {
            throw new GlobalException("只能修改状态未”待提交“，”未通过“的单据");
        }
        //修改收发类型和出库日期和备注，文件路径
        pickingReturns.setTransceiverType(pickingReturnsVo.getTransceiverType());
        pickingReturns.setDateDelivery(pickingReturnsVo.getDateDelivery());
        pickingReturns.setRemark(pickingReturnsVo.getRemark());
        pickingReturns.setFilePath(pickingReturnsVo.getFilePath());
        pickingReturns.setPlannedWeight(list.size());
//        updateById(pickingReturns);
        //查出出库单号
        String wodDocNum = pickingReturns.getWodDocNum();
        //删除此出库单号对应的所有明细
        int delete = pickingReturnsDetailMapper.delete(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, wodDocNum));
        if (delete > 0) {
//            int insert = 0;

            //新增出库明细
            List<PickingReturnsDetail> resultList = new ArrayList<>();
            for (PickingReturnsDetaillVo pickingReturnsDetaillVo : list) {
                //新增返工出库单明细
                PickingReturnsDetail pickingReturnsDetaill = new PickingReturnsDetail();
                //添加批次号
                pickingReturnsDetaill.setBatchNumber(pickingReturnsDetaillVo.getBatchNumber());
                //添加产品号码
                pickingReturnsDetaill.setPdoductNumber(pickingReturnsDetaillVo.getPdoductNumber());
                //添加物料id
                pickingReturnsDetaill.setProductId(pickingReturnsDetaillVo.getProductId());
                //添加物料编码
                pickingReturnsDetaill.setItemCode(pickingReturnsDetaillVo.getItemCode());
                //添加状态为待入库
                pickingReturnsDetaill.setWodStatus(1);
                //添加委外退货单号
                pickingReturnsDetaill.setWodDocNum(wodDocNum);

                //添加净重
                pickingReturnsDetaill.setNetWeight(pickingReturnsDetaillVo.getNetWeight());
                //添加物料数量
                pickingReturnsDetaill.setItemNum(pickingReturnsDetaillVo.getItemNum());
                resultList.add(pickingReturnsDetaill);

                //调用feign查询毛重，净重，配比，克重，厚度，幅宽，卷厂，网型，铺网类型，
//                insert = pickingReturnsDetailMapper.insert(pickingReturnsDetaill);
            }
            pickingReturnsDetailService.saveBatch(resultList);
            //调用审核
            if (pickingReturns.getWodStatus() == 4) {
                SysAuditHistoryVo sysAuditHistoryVo = new SysAuditHistoryVo();
                String perms = "warehouse:outbound:subcontout:examine";
                String auditDoc = pickingReturns.getWodDocNum();
                sysAuditHistoryVo.setAuditDoc(auditDoc);
                sysAuditHistoryVo.setPerms(perms);
                Integer integer = remoteExamineService.editHistory(sysAuditHistoryVo);
                if (integer > 0) {
                    //修改采购退货状态为待提交
                    pickingReturns.setWodStatus(1);

                    //修改审核代办状态为已处理
//                    feignService.updateStatus(3,pickingReturns.getWodDocNum(),"委外退货");

                }
            }
            return updateById(pickingReturns);
        } else {
            throw new GlobalException("修改失败");
        }
    }

    /**
     * 查看委外退货单
     *
     * @param id
     * @return
     */
    @Override
    public PickingReturnsDto view(Long id) {
        //根据字典查询收发类型
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_returns_type");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        //查询出库信息
        PickingReturnsDto pickingReturnsDto = pickingReturnsMapper.getPickingReturnsById(id);

        //赋值收发类型
        pickingReturnsDto.setTransceiverType(pickingReturnsDto.getTransceiverType() + "");
        pickingReturnsDto.setTransceiverTypeDict(statusMap.get(pickingReturnsDto.getTransceiverType() + ""));

        //赋值单据类型
        pickingReturnsDto.setDocumentTypeDict(DocumentTypeEnum.getValue(Integer.parseInt(pickingReturnsDto.getDocumentType())));
        pickingReturnsDto.setDocumentType(pickingReturnsDto.getDocumentType());

        /*
            获取出库明细
         */
        List<PickingReturnsDetail> pickingPurchaseDetails = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, pickingReturnsDto.getWodDocNum()));

        List<PickingReturnsDetailDto> list = new ArrayList<PickingReturnsDetailDto>();
        for (PickingReturnsDetail pickingReturnsDetail : pickingPurchaseDetails) {
            PickingReturnsDetailDto pp = new PickingReturnsDetailDto();

            pp.setItemName(pickingReturnsDto.getItemName());
            pp.setItemSpec(pickingReturnsDto.getItemSpec());
            if(pickingReturnsDto.getMaterialUnit() != null){
                pp.setMaterialUnitDict(unitByCodeToMap.get(pickingReturnsDto.getMaterialUnit()).getUnitName());
            }
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + pickingReturnsDto.getTenantId(), String.valueOf(pickingReturnsDto.getMaterialId()));
            pp.setAuxiliaryAttribute(statsArray);


            //添加物料编码
            pp.setItemCode(pickingReturnsDetail.getItemCode());
            //添加净重
            pp.setNetWeight(pickingReturnsDetail.getNetWeight());
            //添加物料数量
            pp.setItemNum(pickingReturnsDetail.getItemNum());
            //添加批次号
            pp.setBatchNumber(pickingReturnsDetail.getBatchNumber());
            //添加产品号码
            pp.setPdoductNumber(pickingReturnsDetail.getPdoductNumber());

            list.add(pp);

        }
        pickingReturnsDto.setList(list);
        return pickingReturnsDto;
    }

    /**
     * 委外出库列表查询
     *
     * @param pickingReturnsVo
     * @return
     */
    @Override
    public TableDataInfo<PickingReturnsDto> getList(PickingReturnsVo pickingReturnsVo, PageQuery pageQuery) throws Exception {
        //查询返工出库列表
        Page<PickingReturnsDto> pickingReturnsList = pickingReturnsMapper.getPickingReturnslList(pickingReturnsVo, pageQuery.build());

        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_returns_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //根据字典查出收发类型
        List<SysDictData> receivType = DictUtils.getDictCache("picking_returns_type");
        Map<String, String> typeMap = receivType.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        List<PickingReturnsDto> records = pickingReturnsList.getRecords();
        for (PickingReturnsDto pickingReturnsDto : records) {

            if (pickingReturnsDto.getMaterialUnit() != null) {
                //单位
                pickingReturnsDto.setMaterialUnitDict(unitByCodeToMap.get(pickingReturnsDto.getMaterialUnit()).getUnitName());
            }

//            //如果该物料配置了多单位，就进行单位转换
//            if (pickingReturnsDto.getMaterialMoreUnit() != null) {
//                //转换
//                UnitConversionDto unitConversionDto = unitUtil.atWillunitConversion(pickingReturnsDto.getMaterialUnit(), pickingReturnsDto.getMaterialCode(),
//                    String.valueOf(pickingReturnsDto.getPlannedWeight()), pickingReturnsDto.getMaterialId());
//                if (unitConversionDto != null) {
//                    pickingReturnsDto.setUnitConversion(unitConversionDto.getMaterialMoreUnitNumber());
//                }
//            }
            //单位转换
            String s = unitUtil.unitC(pickingReturnsDto.getMaterialCode(),
                String.valueOf(pickingReturnsDto.getPlannedWeight()),
                pickingReturnsDto.getMaterialId(),
                unitByCodeToMap.get(String.valueOf(pickingReturnsDto.getMaterialUnit())).getUnitName());
            pickingReturnsDto.setUnitConversion(s);

            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + pickingReturnsDto.getTenantId(), String.valueOf(pickingReturnsDto.getMaterialId()));
            pickingReturnsDto.setAuxiliaryAttribute(statsArray);

            //添加单据类型
            pickingReturnsDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(pickingReturnsDto.getDocumentType())));

            //添加收发类型
            pickingReturnsDto.setTransceiverTypeDict(pickingReturnsDto.getTransceiverType() + "");
            pickingReturnsDto.setTransceiverType(typeMap.get(pickingReturnsDto.getTransceiverType() + ""));

            //添加生产方式
            pickingReturnsDto.setGenerationMode(GenerationMethodEnum.getValue(Integer.parseInt(pickingReturnsDto.getGenerationMode())));

            //添加单据状态
            pickingReturnsDto.setWodStatusDict(pickingReturnsDto.getWodStatus());
            pickingReturnsDto.setWodStatus(statusMap.get(pickingReturnsDto.getWodStatus() + ""));

        }
        return TableDataInfo.build(pickingReturnsList);
    }

    @Override
    public List<GetPdaDto> getListPda(PickingReturnsVo pickingReturnsVo) {
        //查询返工出库列表
        List<GetPdaDto> list = pickingReturnsMapper.getPickingReturnslListPda(pickingReturnsVo);

        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_returns_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (GetPdaDto getPdaDto : list) {
            getPdaDto.setWodStatusDict(statusMap.get(getPdaDto.getWodStatus()));
        }

        return list;
    }

    /**
     * 导出
     *
     * @param pickingReturnsVo
     * @return
     */
    @Override
    public List<PickingReturnsExport> getInfoExport(PickingReturnsVo pickingReturnsVo) {

        if (pickingReturnsVo.getIdStr() != null) {
            List<String> idList = Arrays.asList(pickingReturnsVo.getIdStr().split(","));

            pickingReturnsVo.setIds(idList);

        }

        //根据字典查出收发类型
        List<SysDictData> receivType = DictUtils.getDictCache("picking_returns_type");
        Map<String, String> typeMap = receivType.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 网型
        List<SysDictData> meshTypeArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> meshTypeMap = meshTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 铺网类型
        List<SysDictData> layingTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> layingTypeMap = layingTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));


        List<PickingReturnsExport> list = pickingReturnsMapper.getInfoExport(pickingReturnsVo);

        for (PickingReturnsExport pickingReturnsExport : list) {
            pickingReturnsExport.setTransceiverTypeDict(typeMap.get(pickingReturnsExport.getTransceiverTypeDict()));
            pickingReturnsExport.setMaterialNetDict(meshTypeMap.get(pickingReturnsExport.getMaterialNetDict()));
            pickingReturnsExport.setMaterialNetTypeDict(layingTypeMap.get(pickingReturnsExport.getMaterialNetTypeDict()));
        }

        return list;
    }

    /**
     * 委外退货(PDA)
     *
     * @param pickingRestDbVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public PickingRestDbDto outReturns(PickingRestDbVo pickingRestDbVo) throws Exception {
        //出库类型
        String type = pickingRestDbVo.getType();
        //输入值
        String inputValue = pickingRestDbVo.getInputValue();

        PickingRestDbDto pickingRestDbDto = new PickingRestDbDto();

        PickingReturns pickingReturns11 = pickingReturnsMapper.selectById(pickingRestDbVo.getId());

        PublicMaterial publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicMaterial>().lambda().eq(PublicMaterial::getMaterialCode, pickingReturns11.getMaterialCode()));

        //判断是否超收或者超发
        //获取菜单id
        Long menuId = remoteMenuService.getIdByMenuName("委外退货");
        SysDocumentResultDto sysDocument = remoteDocumentService.getInfoConfig(menuId);


        //如果配置了送检,则校验是否配了检验方案
//        if (sysDocument.getDocInspectionMark()==1){
//
//            List<SysDocumentCheckDto> documentCheckDtoList = sysDocument.getDocumentCheckDtoList();
//            if (documentCheckDtoList==null){
//                throw new GlobalException("请先在单据配置中配置送检方案");
//            }
//
//            PickingReturns byId = getById(pickingRestDbVo.getId());
//
//
//            QualitySchemeConfigurationVo qualitySchemeConfigurationVo = new QualitySchemeConfigurationVo();
//            qualitySchemeConfigurationVo.setCategory(publicGoods.getMaterialCategory());
//            qualitySchemeConfigurationVo.setItemRank(documentCheckDtoList.get(0).getCheckSubmit());
//            qualitySchemeConfigurationVo.setMaterialCategory(publicGoods.getMaterialType());
//            qualitySchemeConfigurationVo.setMaterialCode(byId.getMaterialCode());
//            boolean check = qualityFeginService.check(qualitySchemeConfigurationVo);
//
//            if (!check){
//                throw new GlobalException("该物料不存在对应的检验方案");
//
//            }
//        }

        // 扫码出库
        if ("1".equals(type)) {
            //判断扫描的物料条码是否一致
            PickingReturnsDetail pickingReturnsDetail = pickingReturnsDetailMapper.selectOne(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getPdoductNumber, inputValue).eq(PickingReturnsDetail::getWodStatus, 1).eq(PickingReturnsDetail::getWodDocNum, pickingReturns11.getWodDocNum()));
            if (pickingReturnsDetail == null) {
                pickingRestDbDto.setCode("500");
                pickingRestDbDto.setMessage("扫描失败，请核实后扫描");
                return pickingRestDbDto;
            }
            //扫描的物料编码
            String wsiMaterialCode = pickingReturnsDetail.getItemCode();
            //查询委外发货单中的物料编码、
            PickingReturns pickingReturns = pickingReturnsMapper.selectById(pickingRestDbVo.getId());

            if (!pickingReturns.getMaterialCode().equals(wsiMaterialCode)) {
                pickingRestDbDto.setCode("500");
                pickingRestDbDto.setMessage("扫描失败，请核实后扫描");
                return pickingRestDbDto;
            }
            //修改明细状态为已出库
            pickingReturnsDetail.setWodStatus(4);
            //判断是否有检验
            int docInspectionMark = sysDocument.getDocInspectionMark();
            //如果有检验
            if (docInspectionMark == 1) {
                //修改单据明细为待检验
                pickingReturnsDetail.setWodStatus(2);
            } else {
                //判断是否有交接
                int docHandoverMark = sysDocument.getDocHandoverMark();
                //有交接
                if (docHandoverMark == 1) {
                    //修改单据明细为待交接
                    pickingReturnsDetail.setWodStatus(3);

                }
            }
            //修改明细出库数量
            if (pickingReturnsDetail.getOutgoingNumber() == null) {
                pickingReturnsDetail.setOutgoingNumber(1L);
            } else {
                pickingReturnsDetail.setOutgoingNumber(pickingReturnsDetail.getOutgoingNumber() + 1L);
            }

            //修改明细状态
            pickingReturnsDetailMapper.updateById(pickingReturnsDetail);

            //修改返工出库单的单据状态为出库中
            pickingReturns.setWodStatus(6);
            //修改出库重量和出库数量
            Double outgoingWeight = pickingReturns.getOutgoingWeight();
            if (outgoingWeight == null) {
                outgoingWeight = 0.0;
            }
            BigDecimal bigDecimal = new BigDecimal(String.valueOf(outgoingWeight));
            BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(pickingReturnsDetail.getNetWeight()));

            BigDecimal add = bigDecimal.add(bigDecimal1);
            pickingReturns.setOutgoingWeight(add.doubleValue());
            Integer outgoingNumber = pickingReturns.getOutgoingNumber();
            if (outgoingNumber == null) {
                outgoingNumber = 0;
            }
            pickingReturns.setOutgoingNumber(outgoingNumber + 1);
            updateById(pickingReturns);

            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue));
            //修改仓库物料的状态为备料
            wmsStockInfo.setWsiMaterialStatus(5);
            int i = wmsStockInfoMapper.updateById(wmsStockInfo);


            //计划/实际
            pickingRestDbDto.setQuantityIdentification(pickingReturns.getPlannedWeight() + "/" + pickingReturns.getOutgoingNumber());
            //出库数量
            pickingRestDbDto.setAllotNumOut(pickingReturns.getOutgoingNumber() + "");

            pickingRestDbDto.setMessage("物料号码:" + inputValue + ",净重:" + wmsStockInfo.getWsiNetWeight() + ",数量:1" + "录入成功");

            OutboundLog outboundLog = new OutboundLog();
            BeanUtils.copyProperties(wmsStockInfo, outboundLog, new String[]{"id"});
            outboundLogService.save(outboundLog);

//            SubcontractReceipt subcontractReceipt = subcontractReceiptMapper.selectOne(new QueryWrapper<SubcontractReceipt>().lambda().eq(SubcontractReceipt::getReceiptNo, pickingReturns.getConnectionId()));
//            UpdateSubcontractingOrderDataVo updateSubcontractingOrderDataVo = new UpdateSubcontractingOrderDataVo();
//            updateSubcontractingOrderDataVo.setSubcontractingOrderNumber(subcontractReceipt.getSubcontractOrderNo());
//            updateSubcontractingOrderDataVo.setBackWeight(wmsStockInfo.getWsiNetWeight());
//            boolean b = orderFeignService.updateBackOrderData(updateSubcontractingOrderDataVo);
//            if (!b){
//                throw new GlobalException("委外订单服务调用失败");
//            }
            //拣货方案
            SchemeDto point = point(pickingRestDbVo.getId());

            if (point.getCombinationName() != null) {
                pickingRestDbDto.setPickingPrompt(point.getCombinationName());
            }


            //查询当前生产领料单
            PickingReturns pickingReturns1 = pickingReturnsMapper.selectById(pickingRestDbVo.getId());
            //判断是否有超收
            int docHairMark = sysDocument.getDocHairMark();
            //没有超收
            if (docHairMark != 1) {

                //计划出库数量
                int allotAmount = pickingReturns1.getPlannedWeight();
                //实际出库数量
                int allotWeightOut = pickingReturns1.getOutgoingNumber();
                if (allotWeightOut >= allotAmount) {
                    //判断是否有检验或者交接
                    //判断是否有检验
                    int isDocInspectionMark = sysDocument.getDocInspectionMark();
                    //如果有检验
                    if (isDocInspectionMark==1){

                        //修改单据为待检验
                        pickingReturns1.setWodStatus(9);
                        pickingReturnsMapper.updateById(pickingReturns1);
                        return pickingRestDbDto;
                    }
                    //判断是否有交接
                    int docHandoverMark = sysDocument.getDocHandoverMark();
                    //有交接
                    if (docHandoverMark == 1) {
                        //修改单据为待交接
                        pickingReturns1.setWodStatus(10);
                        pickingReturnsMapper.updateById(pickingReturns1);

                    } else {
                        //修改单据为已完成
                        pickingReturns1.setWodStatus(7);
                        //删除库存
                        wmsStockInfoMapper.delete(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue));
                        pickingReturnsMapper.updateById(pickingReturns1);
                    }
                }
            }


        } else if ("2".equals(type)) {
            PickingReturns pickingReturns = pickingReturnsMapper.selectById(pickingRestDbVo.getId());

            //批次出库
            //查询当前物料明细中状态为待出库的物料
            List<PickingReturnsDetail> pickingReturnsDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getBatchNumber, inputValue).eq(PickingReturnsDetail::getWodStatus, 1).eq(PickingReturnsDetail::getWodDocNum, pickingReturns11.getWodDocNum()));

            if (pickingReturnsDetailList.size() == 0) {
                pickingRestDbDto.setCode("500");
                pickingRestDbDto.setMessage("扫描失败，请核实后扫描");
                return pickingRestDbDto;
            }

            //查询当前批次(明细表中物料状态为待出库的物料净重之和)
            Double netWeight = pickingReturnsDetailMapper.getNetWeight(inputValue, pickingReturns.getWodDocNum());

            //查询委外出库单中的物料编码
            PickingReturns pickingReturns1 = pickingReturnsMapper.selectById(pickingRestDbVo.getId());

            List<PickingReturnsDetail> list = new ArrayList<PickingReturnsDetail>();

            List<WmsStockInfo> list1 = new ArrayList<WmsStockInfo>();

            List<OutboundLog> outboundLogList = new ArrayList<OutboundLog>();

            for (PickingReturnsDetail pickingReturnsDetail : pickingReturnsDetailList) {
                //修改明细状态为已出库
                pickingReturnsDetail.setWodStatus(4);
                //判断是否有检验
                int docInspectionMark = sysDocument.getDocInspectionMark();
                //如果有检验
                if (docInspectionMark == 1) {
                    //修改单据明细为待检验
                    pickingReturnsDetail.setWodStatus(2);
                } else {
                    //判断是否有交接
                    int docHandoverMark = sysDocument.getDocHandoverMark();
                    //有交接
                    if (docHandoverMark == 1) {
                        //修改单据明细为待交接
                        pickingReturnsDetail.setWodStatus(3);

                    }
                }
                list.add(pickingReturnsDetail);


                //修改出库重量和出库数量
                Double outgoingWeight = pickingReturns1.getOutgoingWeight();
                if (outgoingWeight == null) {
                    outgoingWeight = 0.0;
                }
                BigDecimal bigDecimal = new BigDecimal(outgoingWeight);
                BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(pickingReturnsDetail.getNetWeight()));

                BigDecimal add = bigDecimal.add(bigDecimal1);
                pickingReturns1.setOutgoingWeight(add.doubleValue());

                Integer outgoingNumber = pickingReturns1.getOutgoingNumber();
                if (outgoingNumber == null) {
                    outgoingNumber = 0;
                }
                pickingReturns1.setOutgoingNumber(outgoingNumber + 1);


                //修改仓库物料的状态为备料
                WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pickingReturnsDetail.getPdoductNumber()));
                wmsStockInfo.setWsiMaterialStatus(5);
                list1.add(wmsStockInfo);

                OutboundLog outboundLog = new OutboundLog();
                BeanUtils.copyProperties(wmsStockInfo, outboundLog, new String[]{"id"});
                outboundLogList.add(outboundLog);

            }
            //修改明细状态
            pickingReturnsDetailService.updateBatchById(list);
            wmsStockInfoMapper.updateBatchById(list1);

            //修改返工出库单的单据状态为出库中
            pickingReturns1.setWodStatus(6);
            updateById(pickingReturns1);

            PickingReturns pickingReturns2 = pickingReturnsMapper.selectById(pickingRestDbVo.getId());
            //返回前端参数
            //计划/实际
            pickingRestDbDto.setQuantityIdentification(pickingReturns2.getPlannedWeight() + "/" + pickingReturns2.getOutgoingNumber());
            //出库数量
            pickingRestDbDto.setAllotNumOut(pickingReturns2.getOutgoingNumber() + "");


            pickingRestDbDto.setMessage("批次号:" + inputValue + ",出库量:" + netWeight + ",数量:" + pickingReturnsDetailList.size() + "录入成功");

            outboundLogService.saveBatch(outboundLogList);

//            SubcontractReceipt subcontractReceipt = subcontractReceiptMapper.selectOne(new QueryWrapper<SubcontractReceipt>().lambda().eq(SubcontractReceipt::getReceiptNo, pickingReturns.getConnectionId()));
//            UpdateSubcontractingOrderDataVo updateSubcontractingOrderDataVo = new UpdateSubcontractingOrderDataVo();
//            updateSubcontractingOrderDataVo.setSubcontractingOrderNumber(subcontractReceipt.getSubcontractOrderNo());
//            updateSubcontractingOrderDataVo.setBackWeight(netWeight);
//            boolean b = orderFeignService.updateBackOrderData(updateSubcontractingOrderDataVo);
//            if (!b){
//                throw new GlobalException("委外订单服务调用失败");
//            }

            //拣货方案
            SchemeDto point = point(pickingRestDbVo.getId());


            if (point.getCombinationName() != null) {
                pickingRestDbDto.setPickingPrompt(point.getCombinationName());
            }

            //判断是否有超收
            int docHairMark = sysDocument.getDocHairMark();
            //没有超收
            if (docHairMark != 1) {

                //计划出库数量
                int allotAmount = pickingReturns2.getPlannedWeight();
                //实际出库数量
                int allotWeightOut = pickingReturns2.getOutgoingNumber();
                if (allotWeightOut >= allotAmount) {
                    //判断是否有检验或者交接
                    //判断是否有检验
                    int isDocInspectionMark = sysDocument.getDocInspectionMark();
                    //如果有检验
                    if (isDocInspectionMark==1){
                        //修改单据为待检验
                        pickingReturns2.setWodStatus(9);
                        pickingReturnsMapper.updateById(pickingReturns2);
                        pickingRestDbDto.setCode("200");
                        return pickingRestDbDto;
                    }
                    //判断是否有交接
                    int docHandoverMark = sysDocument.getDocHandoverMark();
                    //有交接
                    if (docHandoverMark == 1) {
                        //修改单据为待交接
                        pickingReturns2.setWodStatus(10);
                        pickingReturnsMapper.updateById(pickingReturns2);

                    } else {
                        //修改单据为已完成
                        pickingReturns2.setWodStatus(7);
                        //删除库存
                        wmsStockInfoMapper.delete(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue).eq(WmsStockInfo::getWsiMaterialStatus, 5));
                        pickingReturnsMapper.updateById(pickingReturns2);
                    }
                }
            }


            // 扫描撤销
        } else if ("3".equals(type)) {
            //在明细表中查询是否有此条码
            PickingReturns pickingReturns = pickingReturnsMapper.selectById(pickingRestDbVo.getId());


            if (pickingReturns.getWodStatus() != 5 && pickingReturns.getWodStatus() != 6) {
                throw new GlobalException("只能对待出库和出库中的单据进行条码撤销");
            }

            PickingReturnsDetail pickingReturnsDetail = pickingReturnsDetailMapper.selectOne(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getPdoductNumber, inputValue).eq(PickingReturnsDetail::getWodDocNum, pickingReturns11.getWodDocNum()));
            if (pickingReturnsDetail == null) {
                pickingRestDbDto.setCode("500");
                pickingRestDbDto.setMessage("撤销失败");
                return pickingRestDbDto;
            }

            if (1==pickingReturnsDetail.getWodStatus()){
                throw new GlobalException("当前号码未出库,不可撤销");
            }

            //修改库存状态为在库
            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue));
            wmsStockInfo.setWsiMaterialStatus(2);
            wmsStockInfoMapper.updateById(wmsStockInfo);


            OutboundLog outboundLog = outboundLogMapper.selectOne(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialNumber, inputValue));
            //删除日志
            outboundLogService.removeById(outboundLog);

            //修改出库明细状态为待出库
            pickingReturnsDetail.setWodStatus(1);
            pickingReturnsDetailMapper.updateById(pickingReturnsDetail);


            BigDecimal out = new BigDecimal(String.valueOf(pickingReturns.getOutgoingWeight()));
            BigDecimal bigDecimal = new BigDecimal(String.valueOf(wmsStockInfo.getWsiNetWeight()));
            BigDecimal outWeight = out.subtract(bigDecimal);
            //修改出库重量
            pickingReturns.setOutgoingWeight(outWeight.doubleValue());

            //扣除数量
            int num = pickingReturns.getOutgoingNumber();
            pickingReturns.setOutgoingNumber(num - 1);


            int i = pickingReturnsMapper.updateById(pickingReturns);
            if (i <= 0) {
                pickingRestDbDto.setCode("500");
                pickingRestDbDto.setMessage("撤销失败");
            }

//            SubcontractReceipt subcontractReceipt = subcontractReceiptMapper.selectOne(new QueryWrapper<SubcontractReceipt>().lambda().eq(SubcontractReceipt::getReceiptNo, pickingReturns.getConnectionId()));
//            UpdateSubcontractingOrderDataVo updateSubcontractingOrderDataVo = new UpdateSubcontractingOrderDataVo();
//            updateSubcontractingOrderDataVo.setSubcontractingOrderNumber(subcontractReceipt.getSubcontractOrderNo());
//            updateSubcontractingOrderDataVo.setBackWeight(wmsStockInfo.getWsiNetWeight());
//            boolean b = orderFeignService.updateBackOrderDataDelete(updateSubcontractingOrderDataVo);
//            if (!b){
//                throw new GlobalException("委外订单服务调用失败");
//            }

            //删除品质检验单
            //计划/实际
            pickingRestDbDto.setQuantityIdentification(pickingReturns.getPlannedWeight() + "/" + pickingReturns.getOutgoingNumber());
            //出库数量
            pickingRestDbDto.setAllotNumOut(pickingReturns.getOutgoingNumber() + "");

            pickingRestDbDto.setMessage("物料号码:" + inputValue + ",净重:" + pickingReturnsDetail.getNetWeight() + ",数量:1" + "录入成功");
        }
        pickingRestDbDto.setCode("200");
        return pickingRestDbDto;
    }

    /**
     * 委外退货拣货完成
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean subcontractingPicking(Long id) throws Exception {

        //获取菜单id
        Long menuId = remoteMenuService.getIdByMenuName("委外退货");
        SysDocumentResultDto sysDocument = remoteDocumentService.getInfoConfig(menuId);

        // 查出单据信息
        PickingReturns pickingReturns = pickingReturnsMapper.selectById(id);

        PublicMaterial publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicMaterial>().lambda().eq(PublicMaterial::getMaterialCode, pickingReturns.getMaterialCode()));

        // 判断是否有校验
        int docInspectionMark = sysDocument.getDocInspectionMark();
        if (docInspectionMark == 1) {

            // 如果是校验,修改采购退货单据状态为待校验
            pickingReturns.setWodStatus(9);
            return pickingReturnsMapper.updateById(pickingReturns) > 0;
        }

        // 判断是否有交接
        int docHandoverMark = sysDocument.getDocHandoverMark();
        if (docHandoverMark == 1) {
            // 如果是交接,修改采购退货单据状态为待交接
            pickingReturns.setWodStatus(10);
            return pickingReturnsMapper.updateById(pickingReturns) > 0;
        }

        // 判断是否有超发
        int docHairMark = sysDocument.getDocHairMark();

        // 如果是超发,修改采购退货单据状态为完成
        pickingReturns.setWodStatus(7);

        //删除库存
        List list = new ArrayList<WmsStockInfo>();

        List<PickingReturnsDetail> pickingReturnsDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));

        for (PickingReturnsDetail pickingReturnsDetail : pickingReturnsDetailList) {
            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pickingReturnsDetail.getPdoductNumber()));
            list.add(wmsStockInfo);
        }
        wmsStockInfoMapper.deleteBatchIds(list);
        return pickingReturnsMapper.updateById(pickingReturns) > 0;

    }

    /**
     * 委外退货交接
     *
     * @param pickingRestDbVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public PickingRestHandoverDto overProductionReturns(PickingRestDbVo pickingRestDbVo) {
        //获取步骤
        int step = pickingRestDbVo.getExecutionOrder();
        //获取输入值
        String inputValue = pickingRestDbVo.getInputValue();
        //返回值
        PickingRestHandoverDto pickingRestHandoverDto = new PickingRestHandoverDto();
        //获取菜单id
        Long menuId = remoteMenuService.getIdByMenuName("委外退货");
        //交接方式
        SysDocumentResultDto sysDocument = remoteDocumentService.getInfoConfig(menuId);
        //拿到交接方式
        int jjType = Integer.parseInt(sysDocument.getDocHandoverMethod());

        //根据字典查出单位
        List<SysDictData> unitList = DictUtils.getDictCache("sys_material_unit");
        Map<String, String> unitMap = unitList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        PickingReturns pickingReturns = getById(pickingRestDbVo.getId());

        if (step == 1) {


            //校验员工编号
            R<SysUser> byUserName = remoteUserService.getByUserName(pickingRestDbVo.getInputValue());
            SysUser userInfo = byUserName.getData();

            if (userInfo == null) {
                pickingRestHandoverDto.setResultCode("500");
                pickingRestHandoverDto.setMessage("交接人输入有误,请核对后输入");
                return pickingRestHandoverDto;
            }

            //返回交接人
            pickingRestHandoverDto.setHandoverName(userInfo.getUserName() + "-" + userInfo.getNickName());
            pickingRestHandoverDto.setDocHandoverMethod(jjType);


            if (jjType == 1) {
                pickingRestHandoverDto.setMessage("请输入物料条码");
            } else if (jjType == 2) {
                pickingRestHandoverDto.setMessage("请输入批次号");
            } else if (jjType == 3) {
                PickingReturns pickingReturns1 = pickingReturnsMapper.selectById(pickingRestDbVo.getId());

                pickingRestDbVo.setInputValue(pickingReturns1.getWodDocNum());

                //查询物料单位
                PublicMaterial publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicMaterial>().lambda().eq(PublicMaterial::getMaterialCode, pickingReturns1.getMaterialCode()));

                //判断是否存在明细表中
                List<PickingReturnsDetail> pickingReturnsDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, pickingRestDbVo.getInputValue()).eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));
                if (pickingReturnsDetailList == null) {
                    pickingRestHandoverDto.setMessage("交接失败");
                    pickingRestHandoverDto.setResultCode("500");
                    return pickingRestHandoverDto;
                }

                //查询当前单据号在明细中是否存在，且状态为待交接
                List<PickingReturnsDetail> pickingReturnsDetailList1 = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, pickingRestDbVo.getInputValue()).eq(PickingReturnsDetail::getWodStatus, 3));
                if (pickingReturnsDetailList1.size() == 0) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("交接失败,请核实后再录入");
                    return pickingRestHandoverDto;
                } else {
                    //查出当前为待交接状态的单据明细,算出总净重和总数量
                    Double sumPiHao = pickingReturnsDetailMapper.getDoc(pickingRestDbVo.getInputValue());
                    //总数量
                    long sumNum = pickingReturnsDetailList1.size();

                    //出库重量
                    Double allotAmount = pickingReturns.getOutgoingWeight();

                    //返回计划/实际
                    Double overWeight = pickingReturns.getOverWeight();
                    if (overWeight == null) {
                        overWeight = 0.0;
                    }
                    //(实际交接)
                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(overWeight));
                    //查询号码在明细中的重量
                    BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(sumPiHao));
                    BigDecimal add = bigDecimal.add(bigDecimal1);

                    pickingReturns.setOverWeight(add.doubleValue());

                    pickingRestHandoverDto.setQuantityIdentification(allotAmount + "/" + add.toString() + unitMap.get(publicGoods.getMaterialUnit()));


                    //保存交接数量，交接重量
                    Integer overNum = pickingReturns.getOverNum();
                    if (overNum == null) {
                        overNum = 0;
                    }
                    int jjSum = (int) sumNum;
                    pickingReturns.setOverNum(overNum + jjSum);

                    //取出关节人
                    String closeUser = pickingReturns.getCloseMan();
                    if (closeUser == null) {
                        closeUser = "";
                    }
                    String[] split = closeUser.split(",");

                    //获取交接人名称
                    String name = LoginHelper.getUsername();

                    //定义变量记录交接人是否相等
                    int jj = 0;

                    if (closeUser != null && !"".equals(closeUser)) {
                        for (String s : split) {
                            if (!name.equals(s)) {
                                jj = 1;
                            }
                        }
                    } else {
                        pickingReturns.setCloseMan(name);
                    }


                    if (jj == 1) {
                        pickingReturns.setCloseMan("," + name);
                    }
                    pickingReturns.setCloseTime(new Date());


                    //出库/交接
                    pickingRestHandoverDto.setOutHandoverActual(pickingReturns.getOutgoingNumber() + "/" + pickingReturns.getOverNum());

                    for (PickingReturnsDetail pickingReturnsDetail : pickingReturnsDetailList1) {
                        //修改物料状态明细为已出库
                        pickingReturnsDetail.setWodStatus(4);
                        pickingReturnsDetailMapper.updateById(pickingReturnsDetail);
                    }


                    //判断是否所有物料没有待交接的状态
                    List<PickingReturnsDetail> pickingReturnsDetailList2 = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodStatus, 3).eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));

                    if (pickingReturnsDetailList2.size() == 0) {
                        //修改单据状态为已完成
                        pickingReturns.setWodStatus(7);

                        //删除库存
                        List list = new ArrayList<WmsStockInfo>();

                        List<PickingReturnsDetail> pickingReturnsDetailList3 = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));

                        for (PickingReturnsDetail pickingReturnsDetail : pickingReturnsDetailList3) {
                            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pickingReturnsDetail.getPdoductNumber()));
                            if (wmsStockInfo!=null){
                                list.add(wmsStockInfo);
                            }
                        }
                        if (list.size()>0){
                            wmsStockInfoMapper.deleteBatchIds(list);
                        }

                    }
                    boolean b = updateById(pickingReturns);
                    if (!b) {
                        pickingRestHandoverDto.setMessage("交接失败");
                        pickingRestHandoverDto.setResultCode("500");
                        return pickingRestHandoverDto;
                    }

                    //消息提示
                    pickingRestHandoverDto.setMessage("单据号:" + pickingRestDbVo.getInputValue() + ",总净重" + sumPiHao + "数量:" + sumNum + ",交接成功");
                }
            }
            pickingRestHandoverDto.setResultCode("200");
            return pickingRestHandoverDto;
        } else if (step == 2) {
            //如果是单个物料交接
            if (jjType == 1) {
                //查询当前的出库单信息

                //查询物料单位
                PublicMaterial publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicMaterial>().lambda().eq(PublicMaterial::getMaterialCode, pickingReturns.getMaterialCode()));


                //查询出库明细
                PickingReturnsDetail pickingReturnsDetail = pickingReturnsDetailMapper.selectOne(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getPdoductNumber, inputValue).eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));
                if (pickingReturnsDetail == null) {
                    pickingRestHandoverDto.setMessage("交接失败");
                    pickingRestHandoverDto.setMessage("500");
                    return pickingRestHandoverDto;
                }

                //判断当前物料是否属于待交接
                if (3 != pickingReturnsDetail.getWodStatus()) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("不可重复交接");
                    return pickingRestHandoverDto;
                } else {
                    //出库重量
                    Double allotAmount = pickingReturns.getOutgoingWeight();

                    Double overWeight = pickingReturns.getOverWeight();
                    if (overWeight == null) {
                        overWeight = 0.0;
                    }

                    //(实际交接)
                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(overWeight));
                    //查询号码在明细中的重量
                    BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(pickingReturnsDetail.getNetWeight()));
                    BigDecimal add = bigDecimal.add(bigDecimal1);

                    pickingReturns.setOverWeight(add.doubleValue());

                    pickingRestHandoverDto.setQuantityIdentification(allotAmount + "/" + add.toString() + unitMap.get(publicGoods.getMaterialUnit()));

                    Integer overNum = pickingReturns.getOverNum();
                    if (overNum == null) {
                        overNum = 0;
                    }
                    //保存交接数量，交接重量
                    pickingReturns.setOverNum(overNum + 1);

                    //取出关节人
                    String closeUser = pickingReturns.getCloseMan();
                    if (closeUser == null) {
                        closeUser = "";
                    }
                    String[] split = closeUser.split(",");

                    //获取交接人名称
                    String name = LoginHelper.getUsername();

                    //定义变量记录交接人是否相等
                    int jj = 0;

                    if (closeUser != null && !"".equals(closeUser)) {
                        for (String s : split) {
                            if (!name.equals(s)) {
                                jj = 1;
                            }
                        }
                    } else {
                        pickingReturns.setCloseMan(name);
                    }


                    if (jj == 1) {
                        pickingReturns.setCloseMan("," + name);
                    }
                    pickingReturns.setCloseTime(new Date());
                    //出库/交接
                    pickingRestHandoverDto.setOutHandoverActual(pickingReturns.getOutgoingNumber() + "/" + pickingReturns.getOverNum());

                    //修改物料状态明细为已出库
                    pickingReturnsDetail.setWodStatus(4);
                    pickingReturnsDetailMapper.updateById(pickingReturnsDetail);


                    //判断是否所有物料没有待交接的状态
                    List<PickingReturnsDetail> pickingReturnsDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodStatus, 3).eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));
                    if (pickingReturnsDetailList.size() == 0) {
                        //修改单据状态为已完成
                        pickingReturns.setWodStatus(7);

                        //删除库存
                        List list = new ArrayList<WmsStockInfo>();

                        List<PickingReturnsDetail> pickingReturnsDetailList3 = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));

                        for (PickingReturnsDetail pickingReturnsDetail11 : pickingReturnsDetailList3) {
                            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pickingReturnsDetail11.getPdoductNumber()));
                            list.add(wmsStockInfo);
                        }
                        wmsStockInfoMapper.deleteBatchIds(list);

                    }

                    boolean b = updateById(pickingReturns);
                    if (!b) {
                        pickingRestHandoverDto.setMessage("交接失败");
                        pickingRestHandoverDto.setMessage("500");
                        return pickingRestHandoverDto;
                    }

                    //消息提示
                    pickingRestHandoverDto.setMessage("物料号码:" + pickingRestDbVo.getInputValue() + ",净重" + pickingReturnsDetail.getNetWeight() + "数量:1,交接成功");

                }
            } else if (jjType == 2) {

                //查询物料单位
                PublicMaterial publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicMaterial>().lambda().eq(PublicMaterial::getMaterialCode, pickingReturns.getMaterialCode()));

                //判断是否存在明细表中
                List<PickingReturnsDetail> pickingReturnsDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getBatchNumber, pickingRestDbVo.getInputValue()).eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));
                if (pickingReturnsDetailList == null) {
                    pickingRestHandoverDto.setResultCode("500");
                    pickingRestHandoverDto.setMessage("交接失败");
                    return pickingRestHandoverDto;
                }

                //查询当前批号在明细中是否存在，且状态为待交接
                List<PickingReturnsDetail> pickingPurchaseDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getBatchNumber, pickingRestDbVo.getInputValue()).eq(PickingReturnsDetail::getWodStatus, 3).eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));
                if (pickingPurchaseDetailList.size() == 0) {
                    pickingRestHandoverDto.setMessage("500");
                    pickingRestHandoverDto.setMessage("不可重复交接");
                    return pickingRestHandoverDto;
                } else {
                    //查出当前为待交接状态的批次，算出总净重和总数量
                    Double sumPiHao = pickingReturnsDetailMapper.getPici(pickingRestDbVo.getInputValue(), pickingReturns.getWodDocNum());
                    //总数量
                    long sumNum = pickingPurchaseDetailList.size();

                    //出库重量
                    Double allotAmount = pickingReturns.getOutgoingWeight();

                    //返回计划/实际
                    Double overWeight = pickingReturns.getOverWeight();
                    if (overWeight == null) {
                        overWeight = 0.0;
                    }
                    //(实际交接)
                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(overWeight));
                    //查询号码在明细中的重量
                    BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(sumPiHao));
                    BigDecimal add = bigDecimal.add(bigDecimal1);

                    pickingReturns.setOverWeight(add.doubleValue());

                    pickingRestHandoverDto.setQuantityIdentification(allotAmount + "/" + add.toString() + unitMap.get(publicGoods.getMaterialUnit()));


                    //保存交接数量，交接重量
                    Integer overNum = pickingReturns.getOverNum();
                    if (overNum == null) {
                        overNum = 0;
                    }

                    int jjSum = (int) sumNum;
                    pickingReturns.setOverNum(overNum + jjSum);

                    //取出关节人
                    String closeUser = pickingReturns.getCloseMan();
                    if (closeUser == null) {
                        closeUser = "";
                    }
                    String[] split = closeUser.split(",");

                    //获取交接人名称
                    String name = LoginHelper.getUsername();

                    //定义变量记录交接人是否相等
                    int jj = 0;

                    if (closeUser != null && !"".equals(closeUser)) {
                        for (String s : split) {
                            if (!name.equals(s)) {
                                jj = 1;
                            }
                        }
                    } else {
                        pickingReturns.setCloseMan(name);
                    }


                    if (jj == 1) {
                        pickingReturns.setCloseMan("," + name);
                    }
                    pickingReturns.setCloseTime(new Date());

                    //出库/交接
                    pickingRestHandoverDto.setOutHandoverActual(pickingReturns.getOutgoingNumber() + "/" + pickingReturns.getOverNum());

                    for (PickingReturnsDetail pickingReturnsDetail : pickingPurchaseDetailList) {
                        //修改物料状态明细为已出库
                        pickingReturnsDetail.setWodStatus(4);

                    }
                    pickingReturnsDetailService.updateBatchById(pickingPurchaseDetailList);

                    //判断是否所有物料没有待交接的状态
                    List<PickingReturnsDetail> pickingReturnsDetailList1 = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodStatus, 3).eq(PickingReturnsDetail::getWodDocNum, pickingReturns.getWodDocNum()));

                    if (pickingReturnsDetailList1.size() == 0) {
                        //修改单据状态为已完成
                        pickingReturns.setWodStatus(7);
                        //删除库存
                        wmsStockInfoMapper.delete(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, inputValue).eq(WmsStockInfo::getWsiMaterialStatus, 5));

                    }
                    boolean b = updateById(pickingReturns);
                    if (!b) {
                        pickingRestHandoverDto.setResultCode("500");
                        pickingRestHandoverDto.setMessage("交接失败");
                        return pickingRestHandoverDto;
                    }

                    //消息提示
                    pickingRestHandoverDto.setMessage("批次号:" + pickingRestDbVo.getInputValue() + ",总净重" + sumPiHao + "数量:" + sumNum + ",交接成功");
                }
            } else if (jjType == 3) {
                pickingRestHandoverDto.setMessage("请勿重复交接");
                pickingRestHandoverDto.setResultCode("500");

            }
        }
        pickingRestHandoverDto.setResultCode("200");
        return pickingRestHandoverDto;
    }

    /**
     * 委外退货审核
     *
     * @param orderReviewVo
     * @return
     */
    @Override
    public boolean returnReview(OrderReviewVo orderReviewVo) throws Exception {
        PickingReturns pickingOutsource = getById(orderReviewVo.getId());
        if (pickingOutsource.getWodStatus() == 2 || pickingOutsource.getWodStatus() == 3) {
            String perms = "warehouse:outbound:subcontout:examine";
            int isAdopt = orderReviewVo.getIsAdopt();
            String auditDoc = pickingOutsource.getWodDocNum();
            String auditRemarks = orderReviewVo.getReviewComments();
            Long userId = LoginHelper.getUserId();

            SysAuditHistoryVo sysAuditHistoryVo = new SysAuditHistoryVo();
            sysAuditHistoryVo.setPerms(perms);
            sysAuditHistoryVo.setModuleType(9);
            sysAuditHistoryVo.setAuditState(isAdopt);
            sysAuditHistoryVo.setAuditRemarks(auditRemarks);
            sysAuditHistoryVo.setAuditDoc(auditDoc);
            sysAuditHistoryVo.setUserId(userId);


            Integer data = remoteExamineService.getSequence(sysAuditHistoryVo);

            if (data == null) {
                throw new GlobalException("未对该审核进行配置");
            }
            //1:通过，2：审核中，3：没权限 4:该人已经审核过
            if (orderReviewVo.getIsAdopt() == 1) {
                if (data == 1) {
                    pickingOutsource.setWodStatus(5);
                    if (pickingOutsource.getReviewBy() == null) {
                        pickingOutsource.setReviewBy(LoginHelper.getUsername());
                    } else {
                        pickingOutsource.setReviewBy(pickingOutsource.getReviewBy() + "," + LoginHelper.getUsername());
                    }
                    pickingOutsource.setReviewTime(new Date());

//                    feignService.updateStatus(3,pickingOutsource.getWodDocNum(),"委外退货");

                    return updateById(pickingOutsource);
                } else if (data == 2) {
                    pickingOutsource.setWodStatus(3);
                    if (pickingOutsource.getReviewBy() == null) {
                        pickingOutsource.setReviewBy(LoginHelper.getUsername());
                    } else {
                        pickingOutsource.setReviewBy(pickingOutsource.getReviewBy() + "," + LoginHelper.getUsername());
                    }
                    pickingOutsource.setReviewTime(new Date());
                    return updateById(pickingOutsource);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            } else {
                if (data == 1 || data == 2) {
                    pickingOutsource.setWodStatus(4);
                    if (pickingOutsource.getReviewBy() == null) {
                        pickingOutsource.setReviewBy(LoginHelper.getUsername());
                    } else {
                        pickingOutsource.setReviewBy(pickingOutsource.getReviewBy() + "," + LoginHelper.getUsername());
                    }
                    pickingOutsource.setReviewTime(new Date());

//                    //新增审核代办
//                    SysWorkbenchAuditAgentVo sysWorkbenchAuditAgentVo = new SysWorkbenchAuditAgentVo();
//
//                    sysWorkbenchAuditAgentVo.setDocConfig("warehouse:outbound:subcontout:examine");
//                    sysWorkbenchAuditAgentVo.setReceiptName("委外退货");
//                    sysWorkbenchAuditAgentVo.setReceiptNumber(pickingOutsource.getWodDocNum());//委外单号
//                    sysWorkbenchAuditAgentVo.setStatus(2);//待处理
//                    sysWorkbenchAuditAgentVo.setPassFlag("1");
//                    sysWorkbenchAuditAgentVo.setCreateName(pickingOutsource.getCreateUser());
//                    sysWorkbenchAuditAgentVo.setReceiptContent("有单据未通过,请及时查看");
//
//                    feignService.insertAuditAgent(sysWorkbenchAuditAgentVo);

                    return updateById(pickingOutsource);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            }
        } else {
            throw new GlobalException("状态为待审核和审核中的单据才能进行审核");
        }
    }

    /**
     * 修改品质
     *
     * @param updateDocVo
     * @return
     */
    @Override
    public boolean returnUpdateStatus(UpdateDocVo updateDocVo) {
        //获取菜单id
        Long menuId = remoteMenuService.getIdByMenuName("委外退货");
        //交接方式
        SysDocumentResultDto sysDocument = remoteDocumentService.getInfoConfig(menuId);
        //交接方式
        int docHandoverMethod = sysDocument.getDocHandoverMark();

        //判断是否有交接

        //如果有交接，修改单据状态和物料明细状态为代交接
        if (docHandoverMethod == 1) {
            PickingReturns pickingReturns = pickingReturnsMapper.selectOne(new QueryWrapper<PickingReturns>().lambda().eq(PickingReturns::getWodDocNum, updateDocVo.getDocNum()));
            pickingReturns.setWodStatus(10);//待交接
            updateById(pickingReturns);
            List<PickingReturnsDetail> pickingReturnsDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, updateDocVo.getDocNum()));
            for (PickingReturnsDetail pickingReturnsDetail : pickingReturnsDetailList) {
                pickingReturnsDetail.setWodStatus(3);
            }
            return pickingReturnsDetailService.updateBatchById(pickingReturnsDetailList);

        } else {
            PickingReturns pickingReturns = pickingReturnsMapper.selectOne(new QueryWrapper<PickingReturns>().lambda().eq(PickingReturns::getWodDocNum, updateDocVo.getDocNum()));
            pickingReturns.setWodStatus(7);//已完成
            updateById(pickingReturns);
            List<PickingReturnsDetail> pickingReturnsDetailList = pickingReturnsDetailMapper.selectList(new QueryWrapper<PickingReturnsDetail>().lambda().eq(PickingReturnsDetail::getWodDocNum, updateDocVo.getDocNum()));

            List<WmsStockInfo> wmsStockInfoList = new ArrayList<>();

            for (PickingReturnsDetail pickingReturnsDetail : pickingReturnsDetailList) {
                pickingReturnsDetail.setWodStatus(4);

                WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pickingReturnsDetail.getPdoductNumber()));
                wmsStockInfoList.add(wmsStockInfo);
            }
            wmsStockInfoMapper.deleteBatchIds(wmsStockInfoList);
            return pickingReturnsDetailService.updateBatchById(pickingReturnsDetailList);
        }

    }

    /**
     * 拣货方案
     *
     * @param id
     * @return
     */
    @Override
    public SchemeDto point(Long id) {
        PickingReturnsDetail pickingReturnsDetail = pickingReturnsDetailMapper.getKw(id);

        if (pickingReturnsDetail == null) {
            return new SchemeDto();
        }
        String pdoductNumber = pickingReturnsDetail.getPdoductNumber();
        //通过产品编码查出库位id
        WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, pdoductNumber));

        Warehouse warehouse = warehouseMapper.selectOne(new QueryWrapper<Warehouse>().lambda().eq(Warehouse::getId, wmsStockInfo.getWsiStorageLoaction()));
//        Warehouse warehouse = warehouseService.getById(wmsStockInfo.getWsiStorageLoaction());

        SchemeDto schemeDto = new SchemeDto();
        schemeDto.setCombinationName(warehouse.getWarehouseName());
        return schemeDto;
    }


}
